home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1995 June
/
MacFormat 25.iso
/
Shareware City
/
Developers
/
ICProgKit1.0
/
Source
/
ICComponent
/
ICComponent.p
next >
Wrap
Text File
|
1994-11-27
|
7KB
|
267 lines
unit ICComponent;
interface
uses
Components;
function Main (var params: ComponentParameters; storage: Handle): ComponentResult;
implementation
uses
{$ifc undefined THINK_Pascal}
Types, Files, Memory, Errors, ToolUtils,
ICTypes,
{$endc}
ICRAPI, ICCAPI;
const
kICCStart = 0;
kICCStop = 1;
kICCFindConfigFile = 2;
kICCSpecifyConfigFile = 3;
kICCGetSeed = 4;
kICCBegin = 5;
kICCGetPref = 6;
kICCSetPref = 7;
kICCCountPref = 8;
kICCGetIndPref = 9;
kICCEnd = 10;
kICCDefaultFile = 11;
kICCDeletePref = 12;
kICCGetPerm = 13;
kICC_first_select = kICCStart;
kICC_last_select = kICCGetPerm;
type
globalsRecord = record
self: ComponentInstance;
current_target: ComponentInstance;
inst: ICRRecord;
end;
globalsPtr = ^globalsRecord;
globalsHandle = ^globalsPtr;
(* Component Manager routines *)
function ICCICanDo (globals: globalsHandle; selector: integer): ComponentResult;
(* Handle the Component Manager CanDo request.*)
begin
case selector of
kComponentVersionSelect..kComponentOpenSelect, kComponentTargetSelect, {}
kICC_first_select..kICC_last_select:
ICCICanDo := 1;
otherwise
ICCICanDo := 0;
end; (* case *)
end; (* ICCICanDo *)
function ICCIOpen (globals: globalsHandle; self: ComponentInstance): ComponentResult;
(* Handle the Component Manager Open request, mostly delayed until ICCStart. *)
var
err: ComponentResult;
begin
(* create our globals *)
globals := globalsHandle(NewHandle(sizeof(globalsRecord)));
err := MemError;
if err = noErr then begin
globals^^.self := self;
globals^^.current_target := self;
(* tell the Component Manager about them *)
SetComponentInstanceStorage(self, Handle(globals));
end; (* if *)
ICCIOpen := noErr;
end; (* ICCIOpen *)
function ICCIClose (globals: globalsHandle; self: ComponentInstance): ComponentResult;
(* Handle the Component Manager Close request. *)
var
err: ComponentResult;
begin
err := noErr;
if globals <> nil then begin
err := ICRStop(globals^^.inst);
DisposeHandle(Handle(globals));
end; (* if *)
ICCIClose := err;
end; (* ICCIClose *)
function ICCITarget (globals: globalsHandle; new_target: ComponentInstance): ComponentResult;
(* Handle the Component Manager Target. *)
var
err: ComponentResult;
begin
globals^^.current_target := new_target;
ICCITarget := noErr;
end; (* ICCITarget *)
(* Internet Configuration specific routines *)
function ICCIStart (globals: globalsHandle; creator: OSType): ICError;
(* Handle the start request, basically a replacement for the open because we need bonus data (creator). *)
var
err: OSErr;
begin
err := ICRStart(globals^^.inst, creator);
if err = noErr then begin
err := ICCDefaultFileName(globals^^.current_target, globals^^.inst.default_filename);
end; (* if *)
ICCIStart := err;
end; (* ICCIStart *)
function ICCIStop (globals: globalsHandle): ICError;
begin
ICCIStop := ICRStop(globals^^.inst);
end; (* ICCIStop *)
function ICCIFindConfigFile (globals: globalsHandle; count: integer; folders: ICDirSpecArrayPtr): ICError;
begin
ICCIFindConfigFile := ICRFindConfigFile(globals^^.inst, count, folders);
end; (* ICCIFindConfigFile *)
function ICCISpecifyConfigFile (globals: globalsHandle; config: FSSpec): ICError;
begin
ICCISpecifyConfigFile := ICRSpecifyConfigFile(globals^^.inst, config);
end; (* ICCISpecifyConfigFile *)
function ICCIGetSeed (globals: globalsHandle; var seed: longint): ICError;
begin
ICCIGetSeed := ICRGetSeed(globals^^.inst, seed);
end; (* ICCIGetSeed *)
function ICCIGetPerm (globals: globalsHandle; var perm: icPerm): ICError;
begin
ICCIGetPerm := ICRGetPerm(globals^^.inst, perm);
end; (* ICCIGetPerm *)
function ICCIBegin (globals: globalsHandle; perm: ICPerm): ICError;
begin
ICCIBegin := ICRBegin(globals^^.inst, perm);
end; (* ICCIBegin *)
function ICCIGetPref (globals: globalsHandle; key: Str255; var attr: ICAttr; buf: Ptr; var size: longint): ICError;
begin
ICCIGetPref := ICRGetPref(globals^^.inst, key, attr, buf, size);
end; (* ICCIGetPref *)
function ICCISetPref (globals: globalsHandle; key: Str255; attr: ICAttr; buf: Ptr; size: longint): ICError;
begin
ICCISetPref := ICRSetPref(globals^^.inst, key, attr, buf, size);
end; (* ICCISetPref *)
function ICCICountPref (globals: globalsHandle; var count: longint): ICError;
begin
ICCICountPref := ICRCountPref(globals^^.inst, count);
end; (* ICCICountPref*)
function ICCIGetIndPref (globals: globalsHandle; n: longint; var key: Str255): ICError;
begin
ICCIGetIndPref := ICRGetIndPref(globals^^.inst, n, key);
end; (* ICCIGetIndPref *)
function ICCIDeletePref (globals: globalsHandle; key: Str255): ICError;
begin
ICCIDeletePref := ICRDeletePref(globals^^.inst, key);
end; (* ICCIDeletePref *)
function ICCIEnd (globals: globalsHandle): ICError;
begin
ICCIEnd := ICREnd(globals^^.inst);
end; (* ICCIEnd *)
function ICCIDefaultFile (globals: globalsHandle; var name: Str63): ICError;
var
err: ICError;
junk: ICError;
refnum: integer;
strh: StringHandle;
begin
err := noErr;
name := ICdefault_file_name;
refnum := OpenComponentResFile(Component(globals^^.self));
if refnum <= 0 then begin
err := resNotFound;
end; (* if *)
if err = noErr then begin
strh := GetString(ICdefault_file_name_ID);
if strh = nil then begin
err := resNotFound;
end
else begin
name := strh^^;
end; (* if *)
junk := CloseComponentResFile(refnum);
end; (* if *)
ICCIDefaultFile := err;
end; (* ICCIDefaultFile *)
function Main (var params: ComponentParameters; storage: Handle): ComponentResult;
(* Component entry point. It's pretty neat IMHO. *)
var
proc: ProcPtr;
s: signedByte;
begin
proc := nil;
case params.what of
(* Component Manager stuff *)
kComponentVersionSelect:
Main := internetConfigurationComponentInterfaceVersion;
kComponentCanDoSelect:
proc := @ICCICanDo;
kComponentOpenSelect:
proc := @ICCIOpen;
(* Component Manager stuff *)
kComponentCloseSelect:
proc := @ICCIClose;
kComponentTargetSelect:
proc := @ICCITarget;
(* this component type stuff *)
kICCStart:
proc := @ICCIStart;
kICCStop:
proc := @ICCIStop;
kICCFindConfigFile:
proc := @ICCIFindConfigFile;
kICCSpecifyConfigFile:
proc := @ICCISpecifyConfigFile;
kICCGetSeed:
proc := @ICCIGetSeed;
kICCGetPerm:
proc := @ICCIGetPerm;
kICCBegin:
proc := @ICCIBegin;
kICCGetPref:
proc := @ICCIGetPref;
kICCSetPref:
proc := @ICCISetPref;
kICCCountPref:
proc := @ICCICountPref;
kICCGetIndPref:
proc := @ICCIGetIndPref;
kICCDeletePref:
proc := @ICCIDeletePref;
kICCEnd:
proc := @ICCIEnd;
kICCDefaultFile:
proc := @ICCIDefaultFile;
otherwise
Main := badComponentSelector;
end; (* case *)
if proc <> nil then begin
if storage <> nil then begin
s := HGetState(storage);
HLock(storage);
end; (* if *)
Main := CallComponentFunctionWithStorage(storage, params, proc);
if storage <> nil then begin
HSetState(storage, s);
end; (* if *)
end; (* if *)
end; (* Main *)
end. (* ICComponent *)